Click here to Skip to main content
15,887,083 members
Home / Discussions / C#
   

C#

 
GeneralRe: Can I use local method in method Pin
OriginalGriff18-Oct-14 0:10
mveOriginalGriff18-Oct-14 0:10 
GeneralRe: Can I use local method in method Pin
Member 1115157118-Oct-14 0:15
Member 1115157118-Oct-14 0:15 
GeneralRe: Can I use local method in method Pin
OriginalGriff18-Oct-14 0:21
mveOriginalGriff18-Oct-14 0:21 
GeneralRe: Can I use local method in method Pin
BillWoodruff18-Oct-14 1:45
professionalBillWoodruff18-Oct-14 1:45 
GeneralRe: Can I use local method in method Pin
OriginalGriff18-Oct-14 1:55
mveOriginalGriff18-Oct-14 1:55 
AnswerRe: Can I use local method in method Pin
BillWoodruff17-Oct-14 22:31
professionalBillWoodruff17-Oct-14 22:31 
GeneralRe: Can I use local method in method Pin
Member 1115157117-Oct-14 22:43
Member 1115157117-Oct-14 22:43 
QuestionDeepCopy Not Working Pin
Kevin Marois17-Oct-14 8:28
professionalKevin Marois17-Oct-14 8:28 
My DeepCopy method:

public static T DeepCopy<T>(T entity)
{
    if (entity == null)
    {
        throw new ArgumentNullException("Entity cannot be null");
    }

    using (var ms = new MemoryStream())
    {
        var formatter = new BinaryFormatter();
        formatter.Serialize(ms, entity);
        ms.Position = 0;

        return (T)formatter.Deserialize(ms);
    }
}


The entity I'm trying to copy:

[Serializable]
[DataContract]
public class SafetyInfractionEntity : _BaseEntity
{
#region Properties
private int _SafetyInfractionId;
[DataMember]
public int SafetyInfractionId
{
	get { return _SafetyInfractionId; }
	set
	{
		if(_SafetyInfractionId != value)
		{
				_SafetyInfractionId = value;
				IsDirty = true;
				RaisePropertyChanged("SafetyInfractionId");
                RaiseEntityChanged();
		}
	}
}

private int _EmployeeId;
[DataMember]
public int EmployeeId
{
	get { return _EmployeeId; }
	set
	{
		if(_EmployeeId != value)
		{
				_EmployeeId = value;
				IsDirty = true;
				RaisePropertyChanged("EmployeeId");
                RaiseEntityChanged();
        }
	}
}

private int _InfractionTypeId;
[DataMember]
public int InfractionTypeId
{
	get { return _InfractionTypeId; }
	set
	{
		if(_InfractionTypeId != value)
		{
				_InfractionTypeId = value;
				IsDirty = true;
				RaisePropertyChanged("InfractionTypeId");
                RaiseEntityChanged();
        }
	}
}

private LookupEntity _InfractionType;
[DataMember]
public LookupEntity InfractionType
{
    get { return _InfractionType; }
    set
    {
        if (_InfractionType != value)
        {
            _InfractionType = value;
            RaisePropertyChanged("InfractionType");
            RaiseEntityChanged();
        }
    }
}

private DateTime? _InfractionDate;
[DataMember]
public DateTime? InfractionDate
{
    get { return _InfractionDate; }
    set
    {
        if (_InfractionDate != value)
        {
            _InfractionDate = value;
            IsDirty = true;
            RaisePropertyChanged("InfractionDate");
            RaiseEntityChanged();
        }
    }
}

private int _JobRevisionId;
[DataMember]
public int JobRevisionId
{
    get { return _JobRevisionId; }
	set
	{
        if (_JobRevisionId != value)
		{
            _JobRevisionId = value;
				IsDirty = true;
                RaisePropertyChanged("JobRevisionId");
                RaiseEntityChanged();
        }
	}
}

private int _ReportedByEmpId;
[DataMember]
public int ReportedByEmpId
{
	get { return _ReportedByEmpId; }
	set
	{
		if(_ReportedByEmpId != value)
		{
			_ReportedByEmpId = value;
			IsDirty = true;
			RaisePropertyChanged("ReportedByEmpId");
            RaiseEntityChanged();
        }
	}
}

private string _Comments;
[DataMember]
public string Comments
{
	get { return _Comments; }
	set
	{
		if(_Comments != value)
		{
			_Comments = value;
			IsDirty = true;
			RaisePropertyChanged("Comments");
            RaiseEntityChanged();
    }
	}
}

private JobEntity _InfractionJobLocation;
[DataMember]
public JobEntity InfractionJobLocation
{
    get { return _InfractionJobLocation; }
    set
    {
        if (_InfractionJobLocation != value)
        {
            _InfractionJobLocation = value;
            RaisePropertyChanged("InfractionJobLocation");
        }
    }
}
#endregion
}


Using it like this:
private SafetyInfractionEntity originalSelectedInfraction;
.
.
.
private void editInfraction()
{
    originalSelectedInfraction= Utilities.DeepCopy<SafetyInfractionEntity>(SelectedInfraction);

    InfractionEditMode = EditMode.Edit;
    refreshView();
}


It's not copying. Changes to SelectedInfraction also appear in the originalSelectedInfractioncopy.

Anyone see what I'm doing wrong?

Thanks
If it's not broken, fix it until it is

AnswerRe: DeepCopy Not Working Pin
BillWoodruff17-Oct-14 8:42
professionalBillWoodruff17-Oct-14 8:42 
AnswerRe: DeepCopy Not Working Pin
Rob Philpott19-Oct-14 7:46
Rob Philpott19-Oct-14 7:46 
AnswerRe: DeepCopy Not Working Pin
Bernhard Hiller19-Oct-14 22:26
Bernhard Hiller19-Oct-14 22:26 
QuestionC# Socket Communication Pin
Lillepige17-Oct-14 8:17
Lillepige17-Oct-14 8:17 
AnswerRe: C# Socket Communication Pin
Richard Andrew x6417-Oct-14 9:49
professionalRichard Andrew x6417-Oct-14 9:49 
AnswerRe: C# Socket Communication Pin
Dave Kreskowiak17-Oct-14 9:52
mveDave Kreskowiak17-Oct-14 9:52 
AnswerRe: C# Socket Communication Pin
Eddy Vluggen17-Oct-14 10:49
professionalEddy Vluggen17-Oct-14 10:49 
AnswerRe: C# Socket Communication Pin
Cai Wallis-Jones18-Oct-14 1:40
Cai Wallis-Jones18-Oct-14 1:40 
GeneralC sharp file creation at specified time. Pin
kanswal7717-Oct-14 3:54
kanswal7717-Oct-14 3:54 
GeneralRe: C sharp file creation at specified time. Pin
BillWoodruff17-Oct-14 3:58
professionalBillWoodruff17-Oct-14 3:58 
GeneralRe: C sharp file creation at specified time. Pin
kanswal7717-Oct-14 5:53
kanswal7717-Oct-14 5:53 
GeneralRe: C sharp file creation at specified time. Pin
BillWoodruff17-Oct-14 6:25
professionalBillWoodruff17-Oct-14 6:25 
GeneralRe: C sharp file creation at specified time. Pin
kanswal7717-Oct-14 6:34
kanswal7717-Oct-14 6:34 
GeneralRe: C sharp file creation at specified time. Pin
BillWoodruff17-Oct-14 7:47
professionalBillWoodruff17-Oct-14 7:47 
GeneralRe: C sharp file creation at specified time. Pin
kanswal7718-Oct-14 17:24
kanswal7718-Oct-14 17:24 
GeneralRe: C sharp file creation at specified time. Pin
Nicholas Marty17-Oct-14 4:32
professionalNicholas Marty17-Oct-14 4:32 
GeneralRe: C sharp file creation at specified time. Pin
kanswal7718-Oct-14 17:38
kanswal7718-Oct-14 17:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.